﻿using System;
using System.IO;
using System.Reflection;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using log4net;
namespace AnyOffice.general.system.gzzd
{
    public partial class _new : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                GzzdDao dao = new GzzdDao();
                GzzdData data = new GzzdData();
                data.Name = this.txtName.Value;
                data.Type = Convert.ToInt32(this.ddlType.Value);
                if (this.PostDeptId.Value != string.Empty)
                {
                    data.PostDept = this.PostDeptId.Value;
                }
                if (this.AccessUserId.Value != string.Empty)
                {
                    data.AccessUser = this.AccessUserId.Value;
                }
                string str = string.Empty;
                foreach (ListItem item in this.ckblDefaultPriv.Items)
                {
                    if (item.Selected)
                    {
                        str = str + item.Value + ",";
                    }
                }
                if (str != string.Empty)
                {
                    data.DefaultPriv = str;
                }
                if (this.NewUserId.Value != string.Empty)
                {
                    data.NewUser = this.NewUserId.Value;
                }
                if (this.ReadUserId.Value != string.Empty)
                {
                    data.ReadUser = this.ReadUserId.Value;
                }
                string str2 = string.Empty;
                foreach (ListItem item2 in this.ckblReadPriv.Items)
                {
                    if (item2.Selected)
                    {
                        str2 = str2 + item2.Value + ",";
                    }
                }
                if (str2 != string.Empty)
                {
                    data.ReadPriv = str2;
                }
                if (this.EditUserId.Value != string.Empty)
                {
                    data.EditUser = this.EditUserId.Value;
                }
                if (this.DownloadUserId.Value != string.Empty)
                {
                    data.DownloadUser = this.DownloadUserId.Value;
                }
                if (this.ManageUserId.Value != string.Empty)
                {
                    data.ManageUser = this.ManageUserId.Value;
                }
                try
                {
                    int num = dao.Insert(base.Conn, data);
                    if (num != -1)
                    {
                        string path = Server.MapPath("/attachment/gzzd/diskpath" + num.ToString());
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                    this.litMessage.Text = base.ShowError("规章制度目录添加失败！", "new.aspx");
                    return;
                }
                base.CloseConn();
                Response.Redirect("index.aspx");
            }
        } 

    }
}
